﻿namespace SampleMvcApplication.Models {
    using System;
    using System.Web.Mvc;
    using MvcTurbine;
    using MvcTurbine.Web.Models;

    public class FooBinder : IFilterableModelBinder {
        public FooBinder(IModelValidator validator) {
            Validator = validator;
        }

        public IModelValidator Validator { get; set; }

        #region IModelBinder Members

        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
            return Validator.IsValid(bindingContext.Model) ? new FooModel() : null;
        }

        public bool SupportsModelType(Type modelType) {
            return modelType.IsType<FooModel>();
        }

        #endregion
    }
}